<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24" >
            <a-form-item label="表单名称">
              <a-input v-model="queryParam.desformName" placeholder="请输入表单名称"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="表单编码">
              <a-input v-model="queryParam.desformCode" placeholder="请输入表单编码"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button  type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAddSelf">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('在线图表')">导出</a-button>
      <a-upload name="file" :show-upload-list="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" >导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button>批量操作<a-icon type="down" /></a-button>
      </a-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon" />
        已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>
        项
        <a style="margin-left: 24px"  @click="onClearSelected">清空</a>
      </div>
      <a-table
        size="middle"
        bordered
        row-key="id"
        :columns="columns"
        :data-source="grapTemplet.formData"
        :pagination="ipagination"
        :loading="loading"
        :row-selection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
      >
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="configForm">设计表单</a>
          <a-divider type="vertical" />
          <a @click="addForm">表单数据</a>
          <a-divider type="vertical" />
          <a >配置地址</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多<a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </a-table>
    </div>
    <!-- :fullscreen.sync="fullscreen" :switch-fullscreen="switchFullscreen" -->
    <!-- <j-modal
      :fullscreen.sync="fullscreen"
      title="表单设计器"
      :visible.sync="isIframeLoaded"
      @cancel="handleCancleDbSync"
      :destroyOnClose="true"
      :footer="null"
      :bodyStyle="{'padding':'0px'}"
    >
      <iframe
        class="result-wrapper"
        frameborder="0"
        :src="getIframeUrl"
      />
    </j-modal> -->

    <j-modal
      :fullscreen.sync="fullscreen"
      title="表单设计器"
      :visible.sync="isIframeLoaded"
      @cancel="handleCancleDbSync"
      :destroyOnClose="true"
      :footer="null"
      :bodyStyle="{'padding':'0px'}"
    >
    <k-form-design :showHead="false"  />
    </j-modal>

    <div class="add-iframe-preview" v-if="isIframePreviewLoaded">
      <iframe
        ref="previewPage"
        class="result-wrapper"
        frameborder="0"
        :src="getIframePreviewUrl"
      />
    </div>
    <!-- <j-modal
      :fullscreen.sync="fullscreen"
      title="表单新增"
      :visible.sync="isIframePreviewLoaded"
      @cancel="isIframePreviewLoaded = false"
      :destroyOnClose="true"
      :footer="null"
      :bodyStyle="{'padding':'0px'}"
    >

    </j-modal> -->
  </a-card>
</template>

<script>
import { mapState } from 'vuex'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { ACCESS_TOKEN } from '@/store/mutation-types'
export default {
  name: 'DesignFormList',
  components: {
  },
  mixins: [JeecgListMixin],
  computed: {
    ...mapState([
      'grapTemplet'
    ]),
    getIframeUrl() {
      return 'http://localhost:8080?token=' + this.ACCESS_TOKEN_ // + '&formData=' + this.grapTemplet.formData[0].desformDesignJson
    },
    getIframePreviewUrl() {
      return 'http://localhost:8080/#/preview?token=' + this.ACCESS_TOKEN_ + '&formData=' + this.grapTemplet.formData[0].desformDesignJson
    }
  },
  data() {
    // const ellipsis = (v, l = 40) => (`<j-ellipsis value={v} length={l}/>`)
    return {
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '表单名称',
          align: 'center',
          dataIndex: 'desformName'
        },
        {
          title: '表单编码',
          align: 'center',
          dataIndex: 'desformCode'
        },
        {
          title: '移动视图',
          align: 'center',
          dataIndex: 'izMobileView_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/diagram/diagramConfiguration/list',
        deleteBatch: '/diagram/diagramConfiguration/deleteBatch',
        delete: '/diagram/diagramConfiguration/delete',
        importExcelUrl: '/sys/fillRule/importExcel',
        exportXlsUrl: '/sys/fillRule/exportXls'
      },
      isIframeLoaded: false,
      isIframePreviewLoaded: false,
      fullscreen: true,
      switchFullscreen: true,
      ACCESS_TOKEN_: ''

    }
  },
  created() {
    this.ACCESS_TOKEN_ = this.$ls.get(ACCESS_TOKEN)
  },
  methods: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    },
    configForm() {
      this.isIframeLoaded = true
    },
    addForm() {
      this.isIframePreviewLoaded = true
    },
    handleCancleDbSync() { // 关闭
      this.editModalVisible = false
    },
    handleAddSelf() {

    }
  },
  mounted() {
    const that = this
    window.addEventListener('message', function(event) {
      // 此处执行事件
      if (event.data && event.data.type === 'dialogClosed') {
        that.isIframePreviewLoaded = false
      }
    })
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .result-wrapper {
    height: calc(100vh - 60px);
    width: 100%;
    overflow: auto;
    box-sizing: border-box;
  }
  .add-iframe-preview{
    position: fixed;
    top:0px;
    left:0px;
    width: 100%;
    height: 100%;
    z-index: 999;
  }
  .add-iframe-preview iframe{
    height: 100%;
  }
</style>
<style lang="less">

</style>
